using MicroMsg.Common.Utils;
using MicroMsg.Storage;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace MicroMsg.UI.UserContrl
{
	public class ChatImgPanoSlideContainer : UserControl
	{
		public delegate void SlideSelectedChanged(object sender, object object_0);
		private enum SlideType
		{
			SlideToRight,
			SlideToLeft
		}
		private const string TAG = "ChatImgPanoSlideContainer";
		public ChatSlideImgCtrl[] ChatSlideImg = new ChatSlideImgCtrl[3];
		private List<ChatMsg> mChatMsgList = new List<ChatMsg>();
		public int nowIndex;
		private bool bIfInited;
		private int pOldIndex = 1;
		private ChatImgPanoSlideContainer.SlideType mSlideType;
		internal Grid LayoutRoot;
		internal Panorama panoramaCtrl;
		internal PanoramaItem pItem1;
		internal Grid Grid1;
		internal PanoramaItem pItem2;
		internal Grid Grid2;
		internal PanoramaItem pItem3;
		internal Grid Grid3;
		private bool _contentLoaded;
		public event ChatImgPanoSlideContainer.SlideSelectedChanged mSlideSelectedChanged;
		public bool bHasFullImage
		{
			get
			{
				if (this.panoramaCtrl.SelectedIndex >= 0 && this.panoramaCtrl.SelectedIndex <= 2)
				{
					if (this.ChatSlideImg[this.panoramaCtrl.SelectedIndex].hdImageLen != 0)
					{
						if (this.ChatSlideImg[this.panoramaCtrl.SelectedIndex].imageLen != this.ChatSlideImg[this.panoramaCtrl.SelectedIndex].hdImageLen)
						{
							return true;
						}
					}
					return false;
				}
				return false;
			}
		}
		public bool bDownloadingHdImage
		{
			get
			{
				return this.panoramaCtrl.SelectedIndex >= 0 && this.panoramaCtrl.SelectedIndex <= 2 && this.ChatSlideImg[this.panoramaCtrl.SelectedIndex].bDownloadFullImage;
			}
		}
		public bool bDownloadingImage
		{
			get
			{
				return this.panoramaCtrl.SelectedIndex >= 0 && this.panoramaCtrl.SelectedIndex <= 2 && this.ChatSlideImg[this.panoramaCtrl.SelectedIndex].bDownloading;
			}
		}
		public int nHdImageLen
		{
			get
			{
				if (this.panoramaCtrl.SelectedIndex >= 0 && this.panoramaCtrl.SelectedIndex <= 2)
				{
					return this.ChatSlideImg[this.panoramaCtrl.SelectedIndex].hdImageLen;
				}
				return 0;
			}
		}
		public string CurrentImgSrc
		{
			get
			{
				if (this.panoramaCtrl.SelectedIndex >= 0 && this.panoramaCtrl.SelectedIndex <= 2)
				{
					return this.ChatSlideImg[this.panoramaCtrl.SelectedIndex].mCuImgStr;
				}
				return "";
			}
		}
		public Image CurrentImgCtrl
		{
			get
			{
				if (this.panoramaCtrl.SelectedIndex >= 0 && this.panoramaCtrl.SelectedIndex <= 2)
				{
					return this.ChatSlideImg[this.panoramaCtrl.SelectedIndex].ShowImg;
				}
				return null;
			}
		}
		public bool bCurrentImgScaled
		{
			get
			{
				return this.panoramaCtrl.SelectedIndex >= 0 && this.panoramaCtrl.SelectedIndex <= 2 && this.ChatSlideImg[this.panoramaCtrl.SelectedIndex].transform.get_ScaleX() != 1.0;
			}
		}
		public List<ChatMsg> chatMsgList
		{
			get
			{
				return this.mChatMsgList;
			}
			set
			{
				this.mChatMsgList = value;
			}
		}
		public ChatImgPanoSlideContainer()
		{
			this.InitializeComponent();
			this.panoramaCtrl.set_Visibility(1);
			this.panoramaCtrl.DefaultItem = this.panoramaCtrl.get_Items().get_Item(1);
			base.add_Loaded(new RoutedEventHandler(this.ChatImgPanoSlideContainer_Loaded));
		}
		private void ChatImgPanoSlideContainer_Loaded(object sender, RoutedEventArgs e)
		{
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.panoramaCtrl.set_Visibility(0);
			});
		}
		public void InitData(int nowIdx)
		{
			if (!this.bIfInited)
			{
				this.nowIndex = nowIdx;
				this.InitSlideImage();
				this.bIfInited = true;
			}
		}
		public void PreLoadFirstImg(ChatMsg preMsg)
		{
			this.ChatSlideImg[0] = new ChatSlideImgCtrl();
			this.ChatSlideImg[1] = new ChatSlideImgCtrl();
			this.ChatSlideImg[2] = new ChatSlideImgCtrl();
			this.Grid1.get_Children().Add(this.ChatSlideImg[0]);
			this.Grid2.get_Children().Add(this.ChatSlideImg[1]);
			this.Grid3.get_Children().Add(this.ChatSlideImg[2]);
			this.ChatSlideImg[1].InitView(preMsg);
		}
		private void InitSlideImage()
		{
			if (this.nowIndex > 0)
			{
				this.ChatSlideImg[0].InitView(this.chatMsgList.get_Item(this.nowIndex - 1));
			}
			else
			{
				this.ChatSlideImg[0].ClearView();
			}
			if (this.nowIndex + 1 < this.chatMsgList.get_Count())
			{
				this.ChatSlideImg[2].InitView(this.chatMsgList.get_Item(this.nowIndex + 1));
				return;
			}
			this.ChatSlideImg[2].ClearView();
		}
		private void panoramaCtrl_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
		{
			if (this.bCurrentImgScaled)
			{
				e.set_Handled(true);
				e.Complete();
			}
		}
		private void panoramaCtrl_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
		{
			if (this.bCurrentImgScaled)
			{
				e.set_Handled(true);
				e.Complete();
			}
			if (this.nowIndex == 0 && e.get_DeltaManipulation().get_Translation().get_X() > 0.0)
			{
				e.set_Handled(true);
				e.Complete();
				return;
			}
			if (this.nowIndex == this.chatMsgList.get_Count() - 1 && e.get_DeltaManipulation().get_Translation().get_X() < 0.0)
			{
				e.set_Handled(true);
				e.Complete();
			}
		}
		private void panoramaCtrl_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
		{
		}
		private void panoramaCtrl_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			int selectedIndex = this.panoramaCtrl.SelectedIndex;
			if (selectedIndex == this.pOldIndex)
			{
				return;
			}
			if ((selectedIndex - this.pOldIndex + 3) % 3 == 1)
			{
				this.mSlideType = ChatImgPanoSlideContainer.SlideType.SlideToRight;
			}
			else
			{
				this.mSlideType = ChatImgPanoSlideContainer.SlideType.SlideToLeft;
			}
			if ((this.mSlideType == ChatImgPanoSlideContainer.SlideType.SlideToLeft && this.nowIndex == 0) || (this.mSlideType == ChatImgPanoSlideContainer.SlideType.SlideToRight && this.nowIndex == this.chatMsgList.get_Count() - 1))
			{
				base.get_Dispatcher().BeginInvoke(delegate
				{
					this.panoramaCtrl.DefaultItem = this.panoramaCtrl.get_Items().get_Item(this.pOldIndex);
				});
				return;
			}
			this.pOldIndex = selectedIndex;
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.RefreshNowIndexImg(this.mSlideType);
				this.LoadNearbyImg(this.mSlideType);
				if (this.mSlideSelectedChanged != null)
				{
					this.mSlideSelectedChanged(this, null);
				}
			});
		}
		public void GoPrevious()
		{
			if (this.nowIndex - 1 < 0)
			{
				Log.smethod_1("ChatImgPanoSlideContainer", "Index error: nowIndex - 1 = " + (this.nowIndex - 1).ToString());
				return;
			}
			int num = (this.panoramaCtrl.SelectedIndex + 2) % 3;
			this.panoramaCtrl.DefaultItem = this.panoramaCtrl.get_Items().get_Item(num);
		}
		public void GoNext()
		{
			if (this.nowIndex + 1 >= this.mChatMsgList.get_Count())
			{
				Log.smethod_1("ChatImgPanoSlideContainer", "Index error: nowIndex + 1 = " + (this.nowIndex + 1).ToString() + " , tloList.Count = " + this.mChatMsgList.get_Count().ToString());
				return;
			}
			int num = (this.panoramaCtrl.SelectedIndex + 1) % 3;
			this.panoramaCtrl.DefaultItem = this.panoramaCtrl.get_Items().get_Item(num);
		}
		private void RefreshNowIndexImg(ChatImgPanoSlideContainer.SlideType sType)
		{
			if (sType == ChatImgPanoSlideContainer.SlideType.SlideToLeft)
			{
				if (this.nowIndex <= 0)
				{
					return;
				}
				this.nowIndex--;
			}
			else
			{
				if (this.nowIndex + 1 >= this.chatMsgList.get_Count())
				{
					return;
				}
				this.nowIndex++;
			}
			if (this.mSlideSelectedChanged != null)
			{
				SlideLocArgs slideLocArgs = new SlideLocArgs();
				slideLocArgs.nowIndex = this.nowIndex;
				this.mSlideSelectedChanged(this, slideLocArgs);
			}
		}
		private void LoadNearbyImg(ChatImgPanoSlideContainer.SlideType sType)
		{
			if (sType == ChatImgPanoSlideContainer.SlideType.SlideToLeft)
			{
				if (this.nowIndex > 0)
				{
					this.ChatSlideImg[(this.panoramaCtrl.SelectedIndex + 2) % 3].InitView(this.chatMsgList.get_Item(this.nowIndex - 1));
				}
				else
				{
					this.ChatSlideImg[(this.panoramaCtrl.SelectedIndex + 2) % 3].ClearView();
				}
			}
			if (sType == ChatImgPanoSlideContainer.SlideType.SlideToRight)
			{
				if (this.nowIndex < this.chatMsgList.get_Count() - 1)
				{
					this.ChatSlideImg[(this.panoramaCtrl.SelectedIndex + 1) % 3].InitView(this.chatMsgList.get_Item(this.nowIndex + 1));
					return;
				}
				this.ChatSlideImg[(this.panoramaCtrl.SelectedIndex + 1) % 3].ClearView();
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/SlideImageView/ChatImgPanoSlideContainer.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panoramaCtrl = (Panorama)base.FindName("panoramaCtrl");
			this.pItem1 = (PanoramaItem)base.FindName("pItem1");
			this.Grid1 = (Grid)base.FindName("Grid1");
			this.pItem2 = (PanoramaItem)base.FindName("pItem2");
			this.Grid2 = (Grid)base.FindName("Grid2");
			this.pItem3 = (PanoramaItem)base.FindName("pItem3");
			this.Grid3 = (Grid)base.FindName("Grid3");
		}
	}
}
